package com.trhui.mallbook.client;

import com.trhui.mallbook.config.MallBookConfig;
import com.trhui.mallbook.domain.common.ApiRequest;
import com.trhui.mallbook.domain.common.BaseResponse;
import com.trhui.mallbook.domain.request.dg.DgRegisterRequest;
import com.trhui.mallbook.domain.request.dg.DgUserRegisterRequest;
import com.trhui.mallbook.domain.request.hf.HfNewRegisterRequest;
import com.trhui.mallbook.domain.request.hf.HfOpenInletRequest;
import com.trhui.mallbook.domain.request.hf.HfRegisterFrontRequest;
import com.trhui.mallbook.domain.request.hf.HfRegisterRequest;
import com.trhui.mallbook.domain.request.xib.XibMessageApplyRequest;
import com.trhui.mallbook.domain.request.xib.XibRegisterRequest;
import com.trhui.mallbook.domain.request.xib.XibTransQueryRequest;
import com.trhui.mallbook.domain.request.yb.YbRegisterRequest;
import com.trhui.mallbook.domain.request.yb.YbRepeatSendRequest;
import com.trhui.mallbook.domain.response.dg.DgRegisterResponse;
import com.trhui.mallbook.domain.response.dg.DgUserRegisterResponse;
import com.trhui.mallbook.domain.response.hf.HfOpenInletResponse;
import com.trhui.mallbook.domain.response.hf.HfRegisterResponse;
import com.trhui.mallbook.domain.response.xib.XibApplyMessageResponse;
import com.trhui.mallbook.domain.response.xib.XibRegisterResponse;
import com.trhui.mallbook.domain.response.xib.XibTransQueryResponse;
import com.trhui.mallbook.domain.response.yb.YbRegisterResponse;
import com.trhui.mallbook.domain.response.yb.YbRepeatSendResponse;
import com.trhui.mallbook.enums.ChannelTypeEnum;
import com.trhui.mallbook.enums.ServerCodeEnum;

/**
 * 子商户注册接口
 *
 * @author huangh
 */
public class RegisterClient extends AbstractClient {
    /**
     * 汇付新后台注册接口，版本固定为1.1.0
     */
    private static final String HF_REGISTER_NEW_VERSION = "1.1.0";
    /**
     * 汇付前台注册接口
     *
     * @param request
     * @return
     */
    public static ApiRequest hfRegisterFront(HfRegisterFrontRequest request) {
        MallBookConfig config = MallBookConfig.getConfig(request.getMerchantNo());
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER_FRONT)
                .channelType(ChannelTypeEnum.HF)
                .date(String.valueOf(System.currentTimeMillis()))
                .version(config.getVersion())
                .build(config.getMerchantPrivateKey());
        return reqApiRequest;
    }

    /**
     * 汇付后台注册接口
     *
     * @param request 注册请求
     * @return 注册响应
     */
    public static BaseResponse<HfRegisterResponse> hfRegister(HfRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfRegisterResponse.class);
    }

    /**
     * 汇付新后台注册接口，版本固定为1.1.0
     *
     * @param request 注册请求
     * @return 注册响应
     */
    public static BaseResponse<HfRegisterResponse> hfRegister(HfNewRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER)
                .version(HF_REGISTER_NEW_VERSION)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfRegisterResponse.class);
    }

    /**
     * 汇付收款子商户进件接口
     *
     * @param request 注册请求
     * @return 注册响应
     */
    public static BaseResponse<HfOpenInletResponse> hfOpenInlet(HfOpenInletRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.OPEN_INLET)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfOpenInletResponse.class);
    }

    /**
     * 易宝后台注册接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<YbRegisterResponse> ybRegister(YbRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER)
                .channelType(ChannelTypeEnum.YB)
                .build();
        return post(reqApiRequest, YbRegisterResponse.class);
    }

    /**
     * 调用 ybRegister 之后调用该接口
     * 易宝重复获取（短验/邮件/电子签章）接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<YbRepeatSendResponse> ybRepeatSend(YbRepeatSendRequest request) {
        ApiRequest apiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REPEAT_SEND)
                .channelType(ChannelTypeEnum.YB)
                .build();
        return post(apiRequest, YbRepeatSendResponse.class);
    }

    /**
     * 厦门国际银行后台注册接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<XibRegisterResponse> xibRegister(XibRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(reqApiRequest, XibRegisterResponse.class);
    }


    /**
     * 厦门国际银行-注册转账结果查询
     *
     * @param request
     * @return
     */
    public static BaseResponse<XibTransQueryResponse> xibTransQuery(XibTransQueryRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.QUERY_TRANSFER)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(reqApiRequest, XibTransQueryResponse.class);
    }

    /**
     * 调用 xibRegister 之后调用该接口
     * 厦门国际银行短信验证码申请接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<XibApplyMessageResponse> xibApplyMessage(XibMessageApplyRequest request) {
        ApiRequest apiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.APPLY_MESSAGE)
                .channelType(ChannelTypeEnum.XIB)
                .build();
        return post(apiRequest, XibApplyMessageResponse.class);
    }
    /**
     * 斗拱-子商户注册
     *
     * @param request
     * @return
     */
    public static BaseResponse<DgUserRegisterResponse> dgUserRegister(DgUserRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.DG_USER_REGISTER)
                .channelType(ChannelTypeEnum.DG)
                .build();
        return post(reqApiRequest, DgUserRegisterResponse.class);
    }

    /**
     * 斗拱后台注册接口
     *
     * @param request 注册请求
     * @return 注册响应
     */
    public static BaseResponse<DgRegisterResponse> dgRegister(DgRegisterRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REGISTER)
                .channelType(ChannelTypeEnum.DG)
                .build();
        return post(reqApiRequest, DgRegisterResponse.class);
    }

}
